package mess;

public class LeeCode_05 {
    public static void main(String[] args) {
        System.out.println(longestPalindrome("cc"));
    }
    private static String longestPalindrome(String s) {
        int len = s.length();
        String res = "";
        String temp;
        int pre;
        int aft;
        for (int i = 0; i < len; i++) {
            temp = "" + s.charAt(i);
            pre = aft = i;
            int count = 0;
            int j = i;
            while (j < len - 1 && s.charAt(j) == s.charAt(j + 1)){
                count++;
                j++;
                aft = i + count;
            }
            for (int k = 0; k < count; k++) {
                temp = "" + temp + s.charAt(i);
            }
            while (pre > 0 && aft < len - 1){
                pre -= 1;
                aft += 1;
                if (s.charAt(pre) == s.charAt(aft)){
                    temp = s.charAt(pre) + temp + s.charAt(aft);
                }else
                    break;
            }
            res = res.length() > temp.length() ? res : temp;
            i += count;
        }
        return res;
    }
}
